<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\BaseAdminController;
use App\Http\Requests\ChapterRequest;
use App\Models\ChapterToDetail;
use App\Models\QueryBuilder;
use Illuminate\Http\Resources\Json\JsonResource;

/*弃用2022-04-26*/

class ChapterToDetailController extends BaseAdminController
{
    //列表
    public function index()
    {
        $data = QueryBuilder::for(ChapterToDetail::query())
            ->fields()
            ->filters(['programmingLanguage.title ', 'chapter_name', 'chapterDetail.title'])
            ->includes(['programmingLanguage', 'chapterDetail'])
            ->sorts()
            ->page();
        return $this->success(JsonResource::collection($data));
    }
    //添加
    public function store(ChapterRequest $request)
    {
        ChapterToDetail::query()->create($request->toArray());
        return $this->success();
    }

    //编辑
    public function update(ChapterToDetail $chaptertodetail, ChapterRequest $request)
    {
        $chaptertodetail->update($request->toArray());
        return $this->success();
    }

    //删除
    public function destroy(ChapterToDetail $chaptertodetail)
    {
        $chaptertodetail->delete();
        return $this->noContent();
    }
}
